﻿<%@ Import Namespace="Cooking.Web.Helpers"%>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IngredientList.ascx.cs" Inherits="Cooking.Web.Views.Recipe.IngredientList" %>

    <%= DateTime.Now.ToShortTimeString() %>
    <fieldset>
        <legend>Ingredients</legend>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="data-table">
            <tr>
                <th scope="col">Quantity</th>
                <th scope="col">Unit Of Measure</th>
                <th scope="col">Preperation</th>
                <th scope="col">Name</th>
                <th></th>
            </tr>
            <tr>
                <td>1</td>
                <td>cup</td>
                <td>lightly shredded</td>
                <td>cheddar cheese</td>
            </tr>
            
            <%
                foreach (var ingredient in Model.Recipe.Ingredients)
                {
                    if (ingredient.Id != Model.EditIngredientId)
                    {
            %>      
                    <tr>
                        <td><%=ingredient.Quantity.ToString()%></td>
                        <td><%=ingredient.UnitOfMeasure%></td>
                        <td><%=ingredient.IngredientPrep %></td>
                        <td><%=ingredient.Ingredient.Name%></td>
                        <td>
                            <%= Html.ActionLinkIf(Model.AllowAddIngredients(), "Edit", "EditIngredient", new { RecipeId = Model.Recipe.Id, IngredientId = ingredient.Id }) %>
                            <%= Html.LiteralIf(Model.AllowAddIngredients(), " | ") %>
                            <%= Html.ActionLinkIf(Model.AllowAddIngredients(), "Delete", "DeleteIngredient", new { RecipeId = Model.Recipe.Id, RecipeIngredientId = ingredient.Id })%>
                        </td>
                    </tr>
            <%
                    }
                    else
                    {
                        Html.BeginForm("UpdateIngredient", "Recipe");
            %>
            
                        <tr>
                            
                            <td><%= Html.TextBox("dto.Quantity", ingredient.Quantity)%></td>
                            <td><%= Html.TextBox("dto.UnitOfMeasure", ingredient.UnitOfMeasure)%></td>
                            <td><%= Html.TextBox("dto.IngredientPrep")%></td>
                            <td><%= ingredient.Ingredient.Name %></td>
                            <td>
                                <%= Html.Hidden("dto.RecipeIngredientId", ingredient.Id) %>
                                <%= Html.Hidden("dto.RecipeId", Model.Recipe.Id)%>
                                <input class="button button-big" name="Submit" type="Button" value="Save"  />
                            </td>
                        </tr>
            <%                    
                    Html.EndForm();
                    }
                } 
                
                if (Model.AllowAddIngredients())
                {
                    //Html.BeginForm("AddIngredient", "Recipe");
            %>
            
                    <tr>
                        <td><%= Html.TextBox("addDto.Quantity")%></td>
                        <td><%= Html.TextBox("addDto.UnitOfMeasure")%></td>
                        <td><%= Html.TextBox("addDto.IngredientPrep") %></td>
                        <td><%= Html.TextBox("addDto.IngredientName")%></td>
                        <td>
                            <%= Html.Hidden("addDto.RecipeId", Model.Recipe.Id)%>
                            <input class="button button-big" name="Submit" type="Button" onclick="AddIngredient()" value="Add"  />
                        </td>
                    </tr>
            <%                    
                    //Html.EndForm();
                }
            %>
        </table>
    </fieldset>